<template>
  <div>
    <div>
      <el-card style="margin-bottom: 10px">
        <div
          style="
            display: flex;
            flex-direction: row;
            justify-content: space-between;
          "
        >
          <div>
            <div class="verticalBar"></div>
            <span style="color: #1074fd">长尾词管理</span>
          </div>
        </div>
      </el-card>
    </div>
    <div>
      <el-card>
        <el-form
          :inline="true"
          class="demo-form-inline"
          ref="filterCondition"
          :model="filterCondition"
        >
          <el-form-item label="简介名称">
            <el-input
              placeholder="请输入"
              v-model="filterCondition.profileName"
            ></el-input>
          </el-form-item>
          <el-form-item label="状态" label-width="100px">
            <el-select v-model="filterCondition.state" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-date-picker
            v-model="filterCondition.time"
            type="daterange"
            format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            class="ml-16"
          >
          </el-date-picker>
          <div class="block">
            <el-form-item>
              <el-button type="primary" @click="navToCreateTailWord"
                >长尾词生成</el-button
              >
              <el-button class="ml-96" type="primary" @click="filterTable"
                >查询</el-button
              >
              <el-button
                class=""
                type="info"
                @click="resetFilter('filterCondition')"
                >清空条件</el-button
              >
            </el-form-item>
          </div>
        </el-form>
      </el-card>
    </div>
    <div class="mt-2">
      <el-card>
        <el-table
          :data="
            tableData.slice(
              (currentPage - 1) * pagesize,
              currentPage * pagesize
            )
          "
          border
          stripe
          style="width: 100%"
        >
          <el-table-column prop="id" label="ID" width="180"> </el-table-column>
          <el-table-column prop="introduce" label="简介名称" width="180">
          </el-table-column>
          <el-table-column prop="content" label="内容" ref="tailwordContent">
          </el-table-column>
          <el-table-column prop="createTime" label="生成时间">
          </el-table-column>

          <el-table-column prop="operations" label="操作" width="300">
            <template slot-scope="scope">
              <div class="text-center">
                <el-button
                  type="primary"
                  size="mini"
                  @click="checkTailWord(scope)"
                  >查看</el-button
                >
                <el-button
                  type="primary"
                  size="mini"
                  @click="updateTailwordpre(scope)"
                  >修改</el-button
                >
                <el-switch
                  class="ml-4"
                  v-model="scope.row.enabled"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  :active-value="1"
                  :inactive-value="0"
                  @change="banTailWord(scope)"
                >
                </el-switch>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="text-center mt-2">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            :page-size="pagesize"
            @current-change="current_change"
          >
          </el-pagination>
        </div>
      </el-card>
    </div>
    <el-dialog
      :visible.sync="tailwordContentVis"
      width="40%"
      style="width: 2000px"
      class="rounded"
    >
      <div>
        <el-card style="margin-bottom: 10px">
          <div
            style="
              display: flex;
              flex-direction: row;
              justify-content: space-between;
            "
          >
            <div>
              <div class="verticalBar"></div>
              <span style="color: #1074fd">长尾词查看</span>
            </div>
          </div>
        </el-card>
      </div>
      <div class="middle_div ml-10">
        <div>
          <!-- <span class="input_div">长尾词</span> -->
          <!-- <div class="border-solid border-2 h-40 rounded overflow-y-scroll">
            {{ checkTailWordContent }}
          </div> -->

          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="checkTailWordContent"
            class="input_div"
          >
          </el-input>
        </div>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="updateBox" width="30%" style="width: 2000px">
      <div>
        <el-card style="margin-bottom: 10px">
          <div
            style="
              display: flex;
              flex-direction: row;
              justify-content: space-between;
            "
          >
            <div>
              <div class="verticalBar"></div>
              <span style="color: #1074fd">长尾词生成</span>
            </div>
          </div>
        </el-card>
      </div>
      <div class="middle_div">
        <span>简介名称：</span>
        <el-input
          v-model="introduce"
          placeholder="请输入内容"
          style="width: 400px"
        ></el-input>

        <div>
          <span>内容：</span>
          <el-input
            v-model="content"
            placeholder="请输入内容"
            style="width: 400px"
            class="ml-6 mt-6"
          ></el-input>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="updateBox = false">取 消</el-button>
        <el-button type="primary" @click="updateTailwordNext">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import video from "@/network/api/video";

export default {
  data() {
    return {
      options: [
        {
          value: "1",
          label: "启用",
        },
        {
          value: "0",
          label: "关闭",
        },
      ],
      filterCondition: {
        state: "",
        time: "",
        profileName: "",
      },
      updateBox: false,
      pagesize: 10,
      currentPage: 1,
      total: 0,
      checkTailWordContent: "",
      value: 1,
      tailwordContentVis: false,
      tableData: [],
      introduce: "",
      content: "",
      id: 0,
    };
  },
  mounted() {
    this.queryData();
  },
  methods: {
    resetFilter(formName) {
      this.$refs[formName].resetFields();
    },
    navToCreateTailWord() {
      this.$router.push("/ems/VideoSynthesis/CreateTailWord");
    },
    filterTable() {
      const info = JSON.parse(localStorage.getItem("updateUserInfo"));
      const data = {
        organId: info.organId + "",
        introduce: this.filterCondition.profileName,
        enabled: this.filterCondition.state,
        // startTime: '',
        // endTime: '',
        pageSize: "10000000",
        pageNum: "1",
      };
      video.queryTail(data).then((res) => {
        res.data.data.records[0].enabled = parseInt(
          res.data.data.records[0].enabled
        );
        this.tableData = [];
        res.data.data.records.forEach((item) => {
          this.tableData.unshift(item);
        });
      });
    },
    checkTailWord(scope) {
      this.checkTailWordContent = scope.row.content;
      this.tailwordContentVis = true;
      console.log(scope);
    },
    queryData() {
      const info = JSON.parse(localStorage.getItem("updateUserInfo"));
      const data = {
        organId: info.organId + "",
        pageSize: "10000000",
        pageNum: "1",
      };
      video.queryTail(data).then((res) => {
        this.total = res.data.data.records.length;
        res.data.data.records.forEach((item) => {
          item.enabled = parseInt(item.enabled);
          this.tableData.unshift(item);
        });
      });
    },
    current_change(currentPage) {
      this.currentPage = currentPage;
    },
    banTailWord(scope) {
      const info = JSON.parse(localStorage.getItem("updateUserInfo"));
      const data = {
        id: scope.row.id + "",
        enabled: scope.row.enabled + "",
      };
      video.banTailword(data).then((res) => {
        console.log(res);
      });
    },
    updateTailwordpre(scope) {
      this.updateBox = true;
      this.id = scope.row.id;
    },
    updateTailwordNext() {
      this.updateBox = false;
      const data = {
        id: this.id,
        introduce: this.introduce,
        content: this.content,
      };

      video.updateTailword(data).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style scoped>
.verticalBar {
  width: 3px;
  height: 18px;
  background: #1074fd;
  display: inline-block;
  vertical-align: top;
  margin-right: 10px;
  margin-top: 2px;
}

/deep/ .el-date-editor .el-range-separator {
  padding: 0;
}

/deep/ .el-dialog__body {
  padding: 0;
}

/deep/ .el-card__body {
  padding: 13px;
}

/deep/ .el-dialog__header {
  padding: 0;
}

.ml-96 {
  margin-left: 48rem;
}

/* .ml-10 {
  margin-left: 1rem;
} */
.input_div {
  margin-top: 10px;
  margin-left: -20px;
  margin-bottom: 20px;
  height: 100px;
}
</style>
